import { h } from "vue";
import { ElImage } from "element-plus";
import { cdn_url } from "@/utils/common";
import type { fileType } from "@/components/Crud/utils/types";

export const functions = {
  /**
   * 图片
   * @param value
   */
  image: function (value) {
    return h(ElImage, {
      src: cdn_url(value),
      fit: "scale-down",
      style: "width: 100px; height: 100px;position: relative;",
      previewSrcList: [cdn_url(value)],
      previewTeleported: true,
      zIndex: 9999
    });
  },
  /**
   * 图片
   * @param value
   */
  images: function (value) {
    if (!Array.isArray(value)) {
      return;
    }
    return h(ElImage, {
      src: cdn_url(value[0]?.url),
      fit: "scale-down",
      style: "width: 100px; height: 100px;position: relative;",
      previewTeleported: true,
      zIndex: 9999,
      previewSrcList: value.map((item: fileType) => {
        return cdn_url(item.url);
      })
    });
  }
};
